package com.atlzk.group.order.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.atlzk.group.order.entity.GroupEntity;
import com.atlzk.group.tgou.entity.KanshopEntity;
import com.atlzk.group.tgou.entity.MiaoShopEntity;
import com.atlzk.group.tgou.entity.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atlzk.group.order.entity.OrderEntity;
import com.atlzk.group.order.service.OrderService;
import com.atlzk.common.utils.PageUtils;
import com.atlzk.common.utils.R;


/**
 * 订单表
 *
 * @author liuzekun
 * @email 2803587841@gmail.com
 * @date 2021-06-18 17:11:50
 */
@RestController
@RequestMapping("order/order")
@CrossOrigin
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:order:list")
    public R list(@RequestParam Map <String, Object> params) {
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list/{umsUserId}")
    //@RequiresPermissions("order:order:list")
    public R list(@RequestParam Map <String, Object> params, @PathVariable("umsUserId") Long umsUserId) {
        PageUtils page = orderService.queryPage(params, umsUserId);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{omsOrderId}")
    //@RequiresPermissions("order:order:info")
    public R info(@PathVariable("omsOrderId") Long omsOrderId) {
        OrderEntity order = orderService.getById(omsOrderId);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:order:save")
    public R save(@RequestBody OrderEntity order) {
        orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:order:update")
    public R update(@RequestBody OrderEntity order) {
        orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:order:delete")
    public R delete(@RequestBody Long[] omsOrderIds) {
        orderService.removeByIds(Arrays.asList(omsOrderIds));

        return R.ok();
    }

    @RequestMapping("/payMoney")
    public R payMoney(@RequestBody OrderEntity order) throws Exception {
        orderService.payMoney(order);
        return R.ok();
    }

    @RequestMapping("/joinTgou/{umsUserId}")
    public R joinTgou(@RequestBody GroupEntity groupEntity, @PathVariable String umsUserId) {
        orderService.joinTgou(groupEntity, umsUserId);
        return R.ok();
    }

    @RequestMapping("/openkan/{umsUserId}")
    public R openkan(@RequestBody KanshopEntity kanshopEntity, @PathVariable("umsUserId") String umsUserId) {
        orderService.openkan(kanshopEntity, umsUserId);
        return R.ok();
    }

    /**
     * 秒杀下单
     */
    @PostMapping("/miao/{umsUserId}")
    public R miao(@RequestBody MiaoShopEntity miaoShopEntity,@PathVariable("umsUserId") String umsUserId) {
        ResultMessage miao = orderService.miao(miaoShopEntity, umsUserId);
        return R.ok().put("result", miao);
    }
}
